#include <vector>
#include <algorithm>

struct Fragment {
    int length; // 总长度（含20B头）
    int offset; // 偏移量（8B为单位）
};

std::vector<Fragment> fragmentPacket(int packetLength, const std::vector<int>& pathMTUs) {
    std::vector<Fragment> fragments;
    fragments.push_back({packetLength, 0});

    for (int mtu : pathMTUs) {
        std::vector<Fragment> temp;
        for (const auto& frag : fragments) {
            if (frag.length <= mtu) {
                temp.push_back(frag);
                continue;
            }

            int data_size = frag.length - 20;
            int max_data = ((mtu - 20) / 8) * 8;
            if (max_data <= 0) {
                temp.push_back(frag);
                continue;
            }

            int remaining = data_size;
            int current_offset = frag.offset;
            while (remaining > 0) {
                int current_data = std::min(max_data, remaining);
                temp.push_back({current_data + 20, current_offset});
                current_offset += current_data / 8;
                remaining -= current_data;
            }
        }
        fragments = temp;
    }
    return fragments;
}